package com.yilin.tms.capital.commons.strategy.tools;

import com.yilin.commons.exception.BusinessException;
import com.yilin.tms.capital.commons.strategy.operation.BankOperation;
import com.yilin.tms.capital.service.IAlipayService;
import com.yilin.tms.core.entity.capital.TradeRecord;
import com.yilin.tms.core.entity.user.account.Account;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

// 支付宝支付

public class AliPayOperation implements BankOperation {//添加需要在BankOperationFactory.class添加判断

    private final IAlipayService alipayService;

    public AliPayOperation(IAlipayService alipayService) {
        this.alipayService = alipayService;
    }

    /**
     * 支付
     * */
    @Override //阿里支付不能用
    public void execute(List<TradeRecord> tradeRecordList, Account account) {
        throw  new BusinessException("支付宝禁止使用策略模式");
    }
    /**
     * 退款
     * */
    @Override
    public TradeRecord executeRefund(TradeRecord tradeRecord, Account account) {
        return alipayService.aliPayRefund(account,tradeRecord);
    }

    /**
     * 查询
     * */
    @Override
    public TradeRecord executeQuery(TradeRecord tradeRecord, Account account) {
        if (tradeRecord.getTradeType() == TradeRecord.TradeType.payment) {
            tradeRecord = alipayService.queryAliPayOrder(account, tradeRecord);
        } else if (tradeRecord.getTradeType() == TradeRecord.TradeType.refund) {
            tradeRecord = alipayService.aliPayRefundQuery(account, tradeRecord);
        }
        return tradeRecord;
    }
}